import React, { useEffect, useState } from 'react';
import Store from './../redux/store';
import * as actions from './../redux/actions';
const Users = () => {
  const [list, setList] = useState(Store.getState().b.users)
  useEffect(() => {
    let unSubscribe = Store.subscribe(() => {
      // console.log(Store.getState().b.users)  // 2??
      setList(Store.getState().b.users)
    });
    return () => {
      unSubscribe();
    }
  })
  return (
    <div>
      <h1>Users Views</h1>
      <button onClick={() => {
        // 模拟表单数据
        let obj = { uname: '李雯艺', uage: 18, usex: '男' }
        // 使用dispatch()分发Action任务
        Store.dispatch(actions.addUser(obj))
      }}>addUser</button>
      <hr />
      <ul>
        {list.map((el) => <li key={el.uid}>{el.uname} -- {el.uage}=={el.usex}</li>)}
      </ul>
    </div>
  );
}

export default Users;
